package main

import (
	"fmt"
	"sync"
	"time"
)

var (
	lock   sync.Mutex
	rwLock sync.RWMutex
	wg     sync.WaitGroup
	x      = 0
)

func write() {
	defer wg.Done()
	lock.Lock()
	x += 1
	lock.Unlock()
}

func read() {
	defer wg.Done()
	lock.Lock()
	fmt.Println(x)
	lock.Unlock()
}

func main() {
	start := time.Now()
	for i := 0; i < 10; i++ {
		wg.Add(1)
		go write()
	}

	for i := 0; i < 1000; i++ {
		wg.Add(1)
		go read()
	}

	wg.Wait()

	fmt.Println(time.Now().Sub(start)) // 6.32941ms 2.7ms
}
